package com.b1502.store2.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.webkit.WebView;
import android.widget.TextView;

import com.b1502.store2.Bean.NewsDetailBean;
import com.b1502.store2.R;
import com.b1502.store2.network.StoreParams;
import com.b1502.store2.util.UrlUtil;
import com.google.gson.Gson;

import org.xutils.common.Callback;
import org.xutils.x;


public class NewsIntentActivity extends AppCompatActivity {

    private TextView news_detail_data;
    private TextView news_detail_title;
    private WebView news_detail_wb;
    private String userId;
    private String userName;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_news_intent);

        news_detail_data = (TextView) findViewById(R.id.news_detail_data);
        news_detail_title = (TextView) findViewById(R.id.news_detail_title);
        news_detail_wb = (WebView) findViewById(R.id.news_detail_wb);
        Intent intent=getIntent();
        userId = intent.getStringExtra("UserId");
        userName = intent.getStringExtra("UserName");
        getData("newsId","648cf203-16f0-4603-b291-40864c472356");
    }


    public void getData(String param, String newsId) {
        StoreParams params = new StoreParams(UrlUtil.GetNews,param,newsId);
        x.http().get(params, new Callback.CommonCallback<String>() {

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onSuccess(String result) {
               Log.d("+++++", result);

                Gson gson=new Gson();
                NewsDetailBean newsDetailBean = gson.fromJson(result, NewsDetailBean.class);
                news_detail_title.setText(newsDetailBean.getTitle());
                news_detail_data.setText(newsDetailBean.getDate());
                news_detail_wb.getSettings().setDefaultTextEncodingName("GBK");
                //news_detail_wb.loadData(newsDetailBean.getContent(),"text/html","utf-8");
                news_detail_wb.loadDataWithBaseURL(null,newsDetailBean.getContent(),"*  /html",  "utf-8", null);
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onFinished() {

            }
        });
    }
}
